package top.hiai.interceptor;

import top.hiai.model.User;
import top.hiai.service.UserService;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import com.jfinal.core.Controller;

/**
* @Author www.hiai.top
* @Email  goodsking@163.com
* @Message 更多资源尽在www.hiai.top,开发者：黄康权
* @Introduction 过滤器
*/

public class LoginSessionInterceptor implements Interceptor {

    public static final String remindKey = "_remind";

	public void intercept(Invocation inv) {
        User LoginUserCache = null;
		Controller c = inv.getController();
		String sessionId = c.getCookie(UserService.sessionIdName);
		if (sessionId != null) {
			LoginUserCache = UserService.getLoginAccountWithSessionId(sessionId);
		
			if (LoginUserCache != null) {
				// 用户登录账号
				c.setAttr(UserService.loginAccountCacheName, LoginUserCache);
			} else {
				c.removeCookie(UserService.sessionIdName); // cookie 登录未成功，证明该 cookie 已经没有用处，删之
			}
		}

		inv.invoke();

       /* if (loginAccount != null) {
            // remind 对象用于生成提醒 tips
            Remind remind = RemindService.me.getRemind(loginAccount.getId());
            if (remind != null) {
                if (remind.getReferMe() > 0 || remind.getMessage() > 0 || remind.getFans() > 0) {
                    c.setAttr(remindKey, remind);
                }
            }
        }*/
	}
}
